package com.aaa.exception;

import com.aaa.entity.ResultCode;
import com.aaa.entity.ResultMsg;
import com.aaa.utils.ResponseUtils;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class OAuthAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    //认证失败的响应结果
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        Class<? extends AuthenticationException> aClass = e.getClass();
        System.out.println(aClass);
        ResultMsg resultMsg = ResultMsg.error(ResultCode.BAD_CLIENT_CREDENTIALS.getCode(), ResultCode.BAD_CLIENT_CREDENTIALS.getMsg());
        ResponseUtils.result(httpServletResponse,resultMsg);

    }
}
